package work43.hashmap;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @Author admin
 * @Date 2019/4/3 10:29
 */
public class Test {
    public static void main(String[] args) {
        HashMap<Integer,Student> hashMap=new HashMap<Integer,Student>();


        Student student1=new Student(1,"张三");
        Student student2=new Student(2,"张si");
        Student student3=new Student(3,"张三");
        hashMap.put(student1.getId(),student1);
        hashMap.put(student2.getId(),student2);
        hashMap.put(student3.getId(),student3);
        System.out.println(hashMap.get(2));

       Set<Integer> set = hashMap.keySet();
        Iterator iterator=set.iterator();
        while (iterator.hasNext()){
            Integer key=(Integer) iterator.next();
            System.out.println(hashMap.get(key));

            Set<Map.Entry<Integer,Student>> set1=hashMap.entrySet();
            Iterator iterator1=set1.iterator();
            while (iterator1.hasNext()){
                Map.Entry<Integer,Student> entry=(Map.Entry<Integer,Student>) iterator1.next();
                Integer key1=entry.getKey();
                Student value=hashMap.get(key1);
                System.out.println(value);
            }

        }

    }

}
